import Vue from 'vue'
import VueRouter from 'vue-router'
import Layout from '../views/Layout/index.vue'
import Login from '../views/Login/index.vue'
import Home from '../views/Home/index.vue'

//异步引入路由
const Goods = () => import('../views/Goods/index.vue')
const Advert = () => import('../views/Advert/index.vue')
const Order = () => import('../views/Order/index.vue')
const Pramas = () => import('../views/Pramas/index.vue')
const Spec = () => import('../views/Pramas/info/spec.vue')
const OrderList = () => import('../views/Order/OrderList/index.vue')
const OrderBack = () => import('../views/Order/OrderBack/index.vue')
const AddGoods = () => import('../views/Goods/AddGoods.vue')
const User = () =>import('../views/User/index.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '',
    component: Layout,
    meta:{
      isLogin:true
    },
    children: [
      {
        path: '/',
        name: 'Home',
        component: Home,
      },
      {
        path: '/goods',
        name: 'Goods',
        component: Goods,
      },
      {
        path: '/add-goods',
        name: 'AddGoods',
        component: AddGoods,
      },
      {
        path: '/advert',
        name: 'Advert',
        component: Advert,
      },
      {
        path: '/user',
        name: 'User',
        component: User,
      },
      {
        path: '/order',
        name: 'Order',
        component: Order,
        redirect:'/order/order-list',
        children: [
          {
            path: 'order-list',
            component: OrderList,
          },
          {
            path: 'order-back',
            component: OrderBack,
          },
        ]
      },
      {
        path: '/pramas',
        name: 'Pramas',
        component: Pramas,
        redirect:'/pramas/spec',
        children:[
          {
            path: 'spec',
            component: Spec,
          }
        ]
      },
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,

  }
]

const router = new VueRouter({
  routes
})
//获取vuex的数据
import store from '../store/index'
//路由拦截
// router.beforeEach((to,from,next)=>{
//   if(to.matched.some(e=>e.meta.isLogin)){
//     let token = store.state.login.userinfo.token
//     if(token){
//       next()
//     }else{
//       next('/login')
//     }
//   }else{    
//     next()
//   }
// })

export default router
